/**
 * 	默认 包含语音题
 */
export const mixins = {
	data() {
		return {
			questionPress: false, //问题是否播放
			isComplete: false, //是否完成问题
			assignment: {}, //问题数据
			chooses: [], //选中的元素
			choosesKey: [] //选中的元素下标
		}
	},
	props: ['question'],
	beforeMount() {
		this.assignment = this.question
	},
	methods: {
		/**
		 *  点击icon 
		 * 	播放/暂停
		 */
		iconTap: function() {
			this.touchAudio()
			this.questionPress ? this.questionPause() : this.questionPlay()
		},
		/**
		 * 	播放问题
		 *  将问题转换成音频播放 [questionNameForAudio]特殊文字
		 * 	改变播放状态
		 */
		questionPlay: async function() {
			const text = this.assignment.questionNameForAudio ? this.assignment.questionNameForAudio : this.assignment.questionName
			const data = await this.parseTextAudio({
				text: text,
				speaker: this.assignment.audioSpeaker ? this.assignment.audioSpeaker : null
			})
			this.dialogueAudio({
				src: data,
				start: () => {
					this.questionPress = true
				},
				end: () => {
					this.questionPress = false
				}
			})
		},
		/**
		 * 	暂停问题播放
		 */
		questionPause: function() {
			this.dialogueAudio({
				play: false
			})
			this.questionPress = false
		},
		/**
		 * 	答案状态
		 *  @param {string} success/error/hidden 成功/失败/隐藏
		 *  @param {number}   
		 */
		optionStatus: function(status, index) {
			this.$set(this.chooses, index, status)
		},
		/**
		 * 	语音回答完毕
		 * 	下一题
		 */
		recordFinish: function(audioData) {
			this.$parent.next({
				isSure: audioData.isAudioWithTexts,
				audioUrl: audioData.audioUrl
			})
		}
	}
}
